<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./jquery3.3.1.js"></script>
</head>
<body>
    <!-- 父亲节点:parent -->
    <div id="box">
        <h2></h2>
    </div>
    <input type="button" value="替换节点">
    <!-- 
        a.replaceWith(b) : 用b替换a
        a.replaceAll(b)  : 用a替换b
     -->
     
    <script>
        $(function(){
            $('input').click(function(){
                 var $h3=$("<h3>我是h3标题</h3>");
                // $("h2").replaceWith($h3);
                $h3.replaceAll($('h2'));
            })  
        })
    </script>
</body>
</html>